import java.util.List;

public class LinkedList {
    public void remove(int key) {
        //空链表
        if(head  = null) {
            return;
        }
        //删除第一个元素
        if(head.val == key) {
            head = head.next;
            return;
        }
        //删除中间元素（建议找前结点进行分开写）
        ListNode cur = head;
        while(cur.next != null) {
            if(cur.next.val == key) {
                ListNode del = cur.next;
                cur.next = del.next;
            }
            else {
                cur = cur.next;
            }
        }
        //没有你要删除的元素
        if(cur == null) {
            return;
        }
    }
}
